<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">airlift</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>  2</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>  3</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">airlift</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>  4</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>  5</span> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">airlift</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="STRN">"object"</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>  6</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>  7</span> </span><span class="WHIT">	</span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Error</span><span class="PUNC">(</span><span class="STRN">"airlift already exists and it is not an object"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>  8</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>  9</span> 
<span class='line'> 10</span> </span><span class="COMM">//Debugging to the web page.  Text sent to this method preppends text</span><span class="WHIT">
<span class='line'> 11</span> </span><span class="COMM">//to the CONTENT_CONTEXT so that it shows up at the top of the web</span><span class="WHIT">
<span class='line'> 12</span> </span><span class="COMM">//page. Very convenient. </span><span class="WHIT">
<span class='line'> 13</span> </span><span class="NAME">airlift.d</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">_debugString</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 14</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 15</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">string</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">HANDLER_NAME</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">":"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">_debugString</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 16</span> </span><span class="WHIT">	</span><span class="NAME">airlift.p</span><span class="PUNC">(</span><span class="STRN">">>>>>>>>>> "</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">string</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 17</span> </span><span class="WHIT">	</span><span class="NAME">CONTENT_CONTEXT.debug</span><span class="PUNC">(</span><span class="STRN">"&lt;div>"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">string</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"&lt;/div>"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 18</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 19</span> 
<span class='line'> 20</span> </span><span class="NAME">airlift.debug</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">_debugString</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 21</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 22</span> </span><span class="WHIT">	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">airlift.d</span><span class="PUNC">(</span><span class="NAME">_debugString</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 23</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 24</span> 
<span class='line'> 25</span> </span><span class="COMM">//ls - load JavaScript scripts </span><span class="WHIT">
<span class='line'> 26</span> </span><span class="NAME">airlift.ls</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">_scriptName</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 27</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 28</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">scriptName</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">_scriptName.replaceAll</span><span class="PUNC">(</span><span class="STRN">"^\\\/"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">replaceAll</span><span class="PUNC">(</span><span class="STRN">"\\.js$"</span><span class="PUNC">,</span><span class="STRN">""</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">".js"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 29</span> </span><span class="WHIT">	</span><span class="NAME">SCRIPTING.loadScript</span><span class="PUNC">(</span><span class="NAME">APP_NAME</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"/"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">scriptName</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 30</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 31</span> 
<span class='line'> 32</span> </span><span class="COMM">//Security checks via the Security context.</span><span class="WHIT">
<span class='line'> 33</span> </span><span class="NAME">airlift.checkAllowed</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">_domainName</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">_method</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">_isCollection</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 34</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 35</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">isCollection</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">airlift.isDefined</span><span class="PUNC">(</span><span class="NAME">_isCollection</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">_isCollection</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 36</span> </span><span class="WHIT">	</span><span class="NAME">SECURITY_CONTEXT.allowed</span><span class="PUNC">(</span><span class="NAME">USER</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">_method</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">APP_PROFILE</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">_domainName</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">isCollection</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> 
<span class='line'> 37</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 38</span> 
<span class='line'> 39</span> </span><span class="COMM">//ar - Create an active record for the provided domain name.  If not</span><span class="WHIT">
<span class='line'> 40</span> </span><span class="COMM">//domain name is provided the default DOMAIN_NAME is used instead.</span><span class="WHIT">
<span class='line'> 41</span> </span><span class="NAME">airlift.ar</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">_domainName</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 42</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 43</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">domainName</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">_domainName</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">DOMAIN_NAME</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Packages.java.lang.String</span><span class="PUNC">(</span><span class="NAME">_domainName</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">toLowerCase</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 44</span> </span><span class="WHIT">	
<span class='line'> 45</span> 	</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">airlift.isDefined</span><span class="PUNC">(</span><span class="NAME">airlift</span><span class="PUNC">[</span><span class="STRN">"create"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">APP_PROFILE.getDomainShortClassName</span><span class="PUNC">(</span><span class="NAME">domainName</span><span class="PUNC">)</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">PRODUCTION_MODE</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 46</span> </span><span class="WHIT">	</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 47</span> </span><span class="WHIT">		</span><span class="NAME">airlift.ls</span><span class="PUNC">(</span><span class="STRN">"airlift/activerecord/"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">APP_PROFILE.getDomainShortClassName</span><span class="PUNC">(</span><span class="NAME">domainName</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">".js"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 48</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 49</span> 
<span class='line'> 50</span> </span><span class="WHIT">	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">airlift</span><span class="PUNC">[</span><span class="STRN">"create"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">APP_PROFILE.getDomainShortClassName</span><span class="PUNC">(</span><span class="NAME">domainName</span><span class="PUNC">)</span><span class="PUNC">]</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 51</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 52</span> 
<span class='line'> 53</span> </span><span class="COMM">//dao - Create the DAO for the provided domain name.  If not</span><span class="WHIT">
<span class='line'> 54</span> </span><span class="COMM">//domain name is provided the default DOMAIN_NAME is used instead.</span><span class="WHIT">
<span class='line'> 55</span> </span><span class="NAME">airlift.dao</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">_domainName</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 56</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 57</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">domainName</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">_domainName</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">DOMAIN_NAME</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Packages.java.lang.String</span><span class="PUNC">(</span><span class="NAME">_domainName</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">toLowerCase</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 58</span> 
<span class='line'> 59</span> </span><span class="WHIT">	</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">airlift.isDefined</span><span class="PUNC">(</span><span class="NAME">airlift</span><span class="PUNC">[</span><span class="STRN">"create"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">APP_PROFILE.getDomainShortClassName</span><span class="PUNC">(</span><span class="NAME">domainName</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"Dao"</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">PRODUCTION_MODE</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 60</span> </span><span class="WHIT">	</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 61</span> </span><span class="WHIT">		</span><span class="NAME">airlift.ls</span><span class="PUNC">(</span><span class="STRN">"airlift/dao/"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">APP_PROFILE.getDomainShortClassName</span><span class="PUNC">(</span><span class="NAME">domainName</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">".js"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 62</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 63</span> 
<span class='line'> 64</span> </span><span class="WHIT">	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">airlift</span><span class="PUNC">[</span><span class="STRN">"create"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">APP_PROFILE.getDomainShortClassName</span><span class="PUNC">(</span><span class="NAME">domainName</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"Dao"</span><span class="PUNC">]</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 65</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 66</span> 
<span class='line'> 67</span> </span><span class="COMM">//validator - Create the validator for the provided domain name.  If not</span><span class="WHIT">
<span class='line'> 68</span> </span><span class="COMM">//domain name is provided the default DOMAIN_NAME is used instead.</span><span class="WHIT">
<span class='line'> 69</span> </span><span class="NAME">airlift.validator</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">_domainName</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 70</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 71</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">domainName</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">_domainName</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">DOMAIN_NAME</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Packages.java.lang.String</span><span class="PUNC">(</span><span class="NAME">_domainName</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">toLowerCase</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 72</span> 
<span class='line'> 73</span> </span><span class="WHIT">	</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">airlift.isDefined</span><span class="PUNC">(</span><span class="NAME">airlift</span><span class="PUNC">[</span><span class="STRN">"create"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">APP_PROFILE.getDomainShortClassName</span><span class="PUNC">(</span><span class="NAME">domainName</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"Validator"</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">PRODUCTION_MODE</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 74</span> </span><span class="WHIT">	</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 75</span> </span><span class="WHIT">		</span><span class="NAME">airlift.ls</span><span class="PUNC">(</span><span class="STRN">"airlift/validation/domain/"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">APP_PROFILE.getDomainShortClassName</span><span class="PUNC">(</span><span class="NAME">domainName</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">".js"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 76</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 77</span> 
<span class='line'> 78</span> </span><span class="WHIT">	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">airlift</span><span class="PUNC">[</span><span class="STRN">"create"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">APP_PROFILE.getDomainShortClassName</span><span class="PUNC">(</span><span class="NAME">domainName</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"Validator"</span><span class="PUNC">]</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 79</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 80</span> 
<span class='line'> 81</span> </span><span class="COMM">//t - create StringTemplate object for a given locale.</span><span class="WHIT">
<span class='line'> 82</span> </span><span class="NAME">airlift.t</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">_templateName</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">_locale</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 83</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 84</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">templateName</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">APP_NAME</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"/"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">_templateName.replaceAll</span><span class="PUNC">(</span><span class="STRN">"^\\\/"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">replaceAll</span><span class="PUNC">(</span><span class="STRN">"\\.st$"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 85</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">template</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">airlift.isDefined</span><span class="PUNC">(</span><span class="NAME">_templateName</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">TEMPLATE.getInstanceOf</span><span class="PUNC">(</span><span class="NAME">templateName</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">airlift.stringTemplate</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 86</span> 
<span class='line'> 87</span> </span><span class="WHIT">	</span><span class="COMM">//TODO figure how this would work using AppEngine.</span><span class="WHIT">
<span class='line'> 88</span> </span><span class="WHIT">	</span><span class="COMM">//var localeProperties = airlift.loadLocaleProperties(_locale);</span><span class="WHIT">
<span class='line'> 89</span> </span><span class="WHIT">	</span><span class="COMM">//template.setAttribute("messages", localeProperties);</span><span class="WHIT">
<span class='line'> 90</span> 
<span class='line'> 91</span> </span><span class="WHIT">	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">template</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 92</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 93</span> 
<span class='line'> 94</span> 
<span class='line'> 95</span> </span><span class="COMM">//p - Convenience method to print using java.lang.System.out.println</span><span class="WHIT">
<span class='line'> 96</span> </span><span class="NAME">airlift.p</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">_message</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 97</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 98</span> </span><span class="WHIT">	</span><span class="NAME">OUT.println</span><span class="PUNC">(</span><span class="NAME">_message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 99</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>100</span> 
<span class='line'>101</span> </span><span class="COMM">//populate an active record with the REQUEST and URI parameters for the</span><span class="WHIT">
<span class='line'>102</span> </span><span class="COMM">//given domain name.  If domain name is not specified the domain</span><span class="WHIT">
<span class='line'>103</span> </span><span class="COMM">//specified by the URI is assumed.</span><span class="WHIT">
<span class='line'>104</span> </span><span class="NAME">airlift.populate</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">_domainName</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>105</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>106</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">activeRecord</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">airlift.ar</span><span class="PUNC">(</span><span class="NAME">_domainName</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>107</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">errorMap</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">activeRecord.populate</span><span class="PUNC">(</span><span class="NAME">REQUEST.getParameterMap</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">REST_CONTEXT</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">METHOD</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>108</span> </span><span class="WHIT">	
<span class='line'>109</span> 	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="NAME">activeRecord</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">errorMap</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>110</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>111</span> 
<span class='line'>112</span> </span><span class="COMM">//get the active record from the datastore for the given domain.</span><span class="WHIT">
<span class='line'>113</span> </span><span class="COMM">//If the domain is not specified retrieve the domain specified by the</span><span class="WHIT">
<span class='line'>114</span> </span><span class="COMM">//URI.</span><span class="WHIT">
<span class='line'>115</span> </span><span class="NAME">airlift.get</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">_id</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">_domainName</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>116</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>117</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">activeRecord</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">airlift.ar</span><span class="PUNC">(</span><span class="NAME">_domainName</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>118</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">id</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">_id</span><span class="PUNC">||</span><span class="NAME">ID</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>119</span> </span><span class="WHIT">	
<span class='line'>120</span> 	</span><span class="NAME">activeRecord.setId</span><span class="PUNC">(</span><span class="NAME">id</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>121</span> 
<span class='line'>122</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">foundRecord</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">activeRecord.get</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>123</span> </span><span class="WHIT">	
<span class='line'>124</span> 	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="NAME">activeRecord</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">foundRecord</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>125</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>126</span> 
<span class='line'>127</span> </span><span class="COMM">/**
<span class='line'>128</span>  * @author Bediako George
<span class='line'>129</span>  * 
<span class='line'>130</span>  * @description This method will collect active records for a domain.
<span class='line'>131</span>  * It may accept a config object that contains configuration
<span class='line'>132</span>  * information for executing the request for the collection.  The
<span class='line'>133</span>  * following may be specified in the config object.
<span class='line'>134</span>  *
<span class='line'>135</span>  * 		&lt;p>offset - Optional. Indicates the start index of the collection.
<span class='line'>136</span>  * 		0 is the default value.&lt;/p>
<span class='line'>137</span>  *
<span class='line'>138</span>  * 		&lt;p>limit - Optional. Indicates the maximum amount that should be returned by
<span class='line'>139</span>  * 		this query. 10 is the default value.&lt;/p>
<span class='line'>140</span>  *
<span class='line'>141</span>  * 		&lt;p>asc - Optional. Set to true for sorting records in ascending order, false
<span class='line'>142</span>  * 		for descending order.  True is the default value.&lt;/p>
<span class='line'>143</span>  *
<span class='line'>144</span>  * 		&lt;p>orderBy - Optional. Name of the property on this domain by
<span class='line'>145</span>  * 		which this collection should be sorted.  Set to "auditPutDate"
<span class='line'>146</span>  * 		as the default value.&lt;/p>
<span class='line'>147</span>  *
<span class='line'>148</span>  * 		&lt;p>returnType- Optional. Determine the type of object that will
<span class='line'>149</span>  * 		hold the collection returned.  Could be "asList" for an
<span class='line'>150</span>  * 		enhanced list, "asIterator" for an enhanced iterator, or
<span class='line'>151</span>  * 		"asIterable" for an enhanced list.  This is set to "asIterator"
<span class='line'>152</span>  * 		by default.&lt;/p>
<span class='line'>153</span>  * 		
<span class='line'>154</span>  * 		&lt;p>filterList - Optional. A list of filter objects that will allow
<span class='line'>155</span>  * 		the developer to further refine the results in the collection.
<span class='line'>156</span>  * 		A filter object has three required properties, namely ...
<span class='line'>157</span>  *
<span class='line'>158</span>  *			&lt;p>(i)"attribute" which is the name of the property on a member
<span class='line'>159</span>  *			entity of the domain collection,&lt;/p>
<span class='line'>160</span>  *
<span class='line'>161</span>  *			&lt;p>(ii)"operatorName" which is the
<span class='line'>162</span>  *			name of the comparison operator to be used to compare this
<span class='line'>163</span>  *			attribute as defined by the Java enum
<span class='line'>164</span>  *			com.google.appengine.api.datastore.Query.FilterOperator&lt;/p>
<span class='line'>165</span>  *
<span class='line'>166</span>  *			&lt;p>(iii)"value" the value that the attribute value must be
<span class='line'>167</span>  *			compared with via the operation specified by
<span class='line'>168</span>  *			"operatorName".&lt;/p>
<span class='line'>169</span>  *		&lt;/p>
<span class='line'>170</span>  *
<span class='line'>171</span>  * @param _arg1 - Optional. If this is a string it will be taken to be the name
<span class='line'>172</span>  * of the domain that should be collected.  If it is not a string it
<span class='line'>173</span>  * must be a config object.
<span class='line'>174</span>  *
<span class='line'>175</span>  * @param _arg2 - Optional, If arg1 is defined then _arg2 is the config
<span class='line'>176</span>  * object.
<span class='line'>177</span>  *
<span class='line'>178</span>  * @return - the active record used to collect the domain results.
<span class='line'>179</span>  * @return - either an enhanced list, a java.util.Iterable, or an enhanced
<span class='line'>180</span>  * java.util.Iterator.  This depends on what was specified in the
<span class='line'>181</span>  * config object.
<span class='line'>182</span>  *
<span class='line'>183</span>  * @example
<span class='line'>184</span>  * if the URI is www.example.com/a/runner
<span class='line'>185</span>  *
<span class='line'>186</span>  * then one could write
<span class='line'>187</span>  * 
<span class='line'>188</span>  * var [runner, runners] = airlift.collect();
<span class='line'>189</span>  *
<span class='line'>190</span>  * and this will retrieve at most ten runners ordered by "auditPutDate"
<span class='line'>191</span>  * in the runners enhanced iterator.
<span class='line'>192</span>  *
<span class='line'>193</span>  * To get the runners
<span class='line'>194</span>  *
<span class='line'>195</span>  * for (var runner in Iterator(runners))
<span class='line'>196</span>  * {
<span class='line'>197</span>  *		LOG.info(runner.json());
<span class='line'>198</span>  * }
<span class='line'>199</span>  *
<span class='line'>200</span>  * or this works as well
<span class='line'>201</span>  *
<span class='line'>202</span>  * runners.forEach(function(_runner) { LOG.info(_runner.json()); });
<span class='line'>203</span>  *
<span class='line'>204</span>  * Also one could do this ...
<span class='line'>205</span>  *
<span class='line'>206</span>  * var [runner, runnersList] = airlift.collect(
<span class='line'>207</span>  * "prorunner",
<span class='line'>208</span>  * {
<span class='line'>209</span>  *	returnType: "asList",
<span class='line'>210</span>  *	orderBy: "firstName",
<span class='line'>211</span>  *	limit:200,
<span class='line'>212</span>  *	offset:100,
<span class='line'>213</span>  *	filterList:[
<span class='line'>214</span>  *	{attribute:"lastName", operatorName:"EQUAL", value:"George"},
<span class='line'>215</span>  *	{attribute:"age", operatorName:"LESS_THAN" value:20}
<span class='line'>216</span>  *	]
<span class='line'>217</span>  * };
<span class='line'>218</span>  *
<span class='line'>219</span>  * and this will return an enhanced list that contains "prorunner"
<span class='line'>220</span>  * active records that have last name "George" and age less than 20
<span class='line'>221</span>  * years old, paginated from 100 to 200, and ordered by the first name.
<span class='line'>222</span>  *
<span class='line'>223</span>  * One may get the runners as shown above.
<span class='line'>224</span>  *
<span class='line'>225</span>  */</span><span class="WHIT">
<span class='line'>226</span> </span><span class="NAME">airlift.collect</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">_arg1</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">_arg2</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>227</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>228</span> </span><span class="WHIT">	</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">_arg1</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">_arg2</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>229</span> </span><span class="WHIT">	</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>230</span> </span><span class="WHIT">		</span><span class="COMM">//_arg1 is the domain name and arg2 the config object</span><span class="WHIT">
<span class='line'>231</span> </span><span class="WHIT">		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">domainName</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">_arg1</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>232</span> </span><span class="WHIT">		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">config</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">_arg2</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>233</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>234</span> </span><span class="WHIT">	</span><span class="KEYW">else</span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">_arg1</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">airlift.isDefined</span><span class="PUNC">(</span><span class="NAME">_arg1.length</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>235</span> </span><span class="WHIT">	</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>236</span> </span><span class="WHIT">		</span><span class="COMM">//_arg1 is a string or java.lang.String and _arg2 os not</span><span class="WHIT">
<span class='line'>237</span> </span><span class="WHIT">		</span><span class="COMM">//defined.</span><span class="WHIT">
<span class='line'>238</span> </span><span class="WHIT">		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">domainName</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">_arg1</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>239</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>240</span> </span><span class="WHIT">	</span><span class="KEYW">else</span><span class="WHIT"> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">_arg1</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">_arg1</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="STRN">'object'</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>241</span> </span><span class="WHIT">	</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>242</span> </span><span class="WHIT">		</span><span class="COMM">//_arg1 is a config object</span><span class="WHIT">
<span class='line'>243</span> </span><span class="WHIT">		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">domainName</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">DOMAIN_NAME</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>244</span> </span><span class="WHIT">		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">config</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">_arg1</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>245</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>246</span> </span><span class="WHIT">	</span><span class="KEYW">else</span><span class="WHIT">
<span class='line'>247</span> </span><span class="WHIT">	</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>248</span> </span><span class="WHIT">		</span><span class="COMM">//nothing was passed in ...</span><span class="WHIT">
<span class='line'>249</span> </span><span class="WHIT">		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">domainName</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">DOMAIN_NAME</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>250</span> </span><span class="WHIT">		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">config</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>251</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>252</span> 
<span class='line'>253</span> </span><span class="WHIT">	</span><span class="NAME">config.limit</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">config.limit</span><span class="PUNC">||</span><span class="NAME">REQUEST.getParameter</span><span class="PUNC">(</span><span class="STRN">"limit"</span><span class="PUNC">)</span><span class="PUNC">||</span><span class="NUMB">10</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>254</span> </span><span class="WHIT">	</span><span class="NAME">config.offset</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">config.offset</span><span class="PUNC">||</span><span class="NAME">REQUEST.getParameter</span><span class="PUNC">(</span><span class="STRN">"offset"</span><span class="PUNC">)</span><span class="PUNC">||</span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>255</span> </span><span class="WHIT">	</span><span class="NAME">config.orderBy</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">config.orderBy</span><span class="PUNC">||</span><span class="NAME">REQUEST.getParameter</span><span class="PUNC">(</span><span class="STRN">"orderBy"</span><span class="PUNC">)</span><span class="PUNC">||</span><span class="STRN">"auditPutDate"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>256</span> </span><span class="WHIT">	
<span class='line'>257</span> 	</span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">evaluateBooleanString</span><span class="PUNC">(</span><span class="NAME">_booleanString</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>258</span> </span><span class="WHIT">	</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>259</span> </span><span class="WHIT">		</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="STRN">"true"</span><span class="PUNC">.</span><span class="NAME">equalsIgnoreCase</span><span class="PUNC">(</span><span class="NAME">_booleanString</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>260</span> </span><span class="WHIT">		</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>261</span> </span><span class="WHIT">			</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">value</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>262</span> </span><span class="WHIT">		</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>263</span> </span><span class="WHIT">		</span><span class="KEYW">else</span><span class="WHIT">
<span class='line'>264</span> </span><span class="WHIT">		</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>265</span> </span><span class="WHIT">			</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">value</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>266</span> </span><span class="WHIT">		</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>267</span> 
<span class='line'>268</span> </span><span class="WHIT">		</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>269</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>270</span> </span><span class="WHIT">	
<span class='line'>271</span> 	</span><span class="NAME">config.asc</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">airlift.isDefined</span><span class="PUNC">(</span><span class="NAME">config.asc</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">config.asc</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">airlift.isDefined</span><span class="PUNC">(</span><span class="NAME">REQUEST.getParameter</span><span class="PUNC">(</span><span class="STRN">"asc"</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">evaluateBooleanString</span><span class="PUNC">(</span><span class="NAME">REQUEST.getParameter</span><span class="PUNC">(</span><span class="STRN">"asc"</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>272</span> </span><span class="WHIT">	
<span class='line'>273</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">activeRecord</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">airlift.ar</span><span class="PUNC">(</span><span class="NAME">domainName</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>274</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">result</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">activeRecord.collect</span><span class="PUNC">(</span><span class="NAME">config</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>275</span> 
<span class='line'>276</span> </span><span class="WHIT">	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="NAME">activeRecord</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">result</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>277</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>278</span> 
<span class='line'>279</span> </span><span class="COMM">/**
<span class='line'>280</span>  * @author Bediako George
<span class='line'>281</span>  * @description
<span class='line'>282</span>  *
<span class='line'>283</span>  * @param _errorMap
<span class='line'>284</span>  *
<span class='line'>285</span>  *
<span class='line'>286</span>  * @return
<span class='line'>287</span>  *
<span class='line'>288</span>  * @example
<span class='line'>289</span>  *
<span class='line'>290</span>  *
<span class='line'>291</span>  */</span><span class="WHIT">
<span class='line'>292</span> </span><span class="NAME">airlift.renderError</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">_errorMap</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>293</span> </span><span class="PUNC">{</span><span class="WHIT">	
<span class='line'>294</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">stringBuffer</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">java.lang.StringBuffer</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> 
<span class='line'>295</span> 
<span class='line'>296</span> 	</span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">errorName</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">Iterator</span><span class="PUNC">(</span><span class="NAME">_errorMap.keySet</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>297</span> </span><span class="WHIT">	</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>298</span> </span><span class="WHIT">		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">errors</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">_errorMap.get</span><span class="PUNC">(</span><span class="NAME">errorName</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>299</span> 
<span class='line'>300</span> </span><span class="WHIT">		</span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">error</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">Iterator</span><span class="PUNC">(</span><span class="NAME">errors</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>301</span> </span><span class="WHIT">		</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>302</span> </span><span class="WHIT">			</span><span class="NAME">stringBuffer.append</span><span class="PUNC">(</span><span class="NAME">Packages.airlift.util.HtmlUtil.toRdfa</span><span class="PUNC">(</span><span class="NAME">APP_NAME</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">error</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">append</span><span class="PUNC">(</span><span class="STRN">"\n"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>303</span> </span><span class="WHIT">		</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>304</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>305</span> 
<span class='line'>306</span> </span><span class="WHIT">	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">stringBuffer.toString</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>307</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>308</span> 
<span class='line'>309</span> </span><span class="NAME">airlift.prepareUri</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">_id</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">_uri</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>310</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>311</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">baseURI</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">airlift.isDefined</span><span class="PUNC">(</span><span class="NAME">_uri</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">airlift.string</span><span class="PUNC">(</span><span class="NAME">_uri</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">URI</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>312</span> </span><span class="WHIT">	
<span class='line'>313</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">uri</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">airlift.string</span><span class="PUNC">(</span><span class="NAME">baseURI</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">replaceAll</span><span class="PUNC">(</span><span class="STRN">"\\/$"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>314</span> 
<span class='line'>315</span> </span><span class="WHIT">	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">uri</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"/"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">_id</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>316</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>317</span> 
<span class='line'>318</span> </span><span class="NAME">airlift.canonicalUri</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">_domainName</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">_id</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>319</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>320</span> </span><span class="WHIT">	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">BASE</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"a/"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">_domainName</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"/"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">_id</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>321</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>322</span> 
<span class='line'>323</span> </span><span class="NAME">airlift.production</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">_productionValue</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">_devValue</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>324</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>325</span> </span><span class="WHIT">	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">PRODUCTION_MODE</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">_productionValue</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">_devValue</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>326</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>327</span> 
<span class='line'>328</span> </span><span class="NAME">airlift.createCalendar</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">_config</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>329</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>330</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">date</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">_config</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">_config.date</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">_config.date</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>331</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">dateOffset</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">_config</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">_config.dateOffset</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">_config.dateOffset</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>332</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">dateOffsetType</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">_config</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">_config.dateOffsetType</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">_config.dateOffsetType</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">Packages.java.util.Calendar.MILLISECOND</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>333</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">timeZone</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">_config</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">_config.timeZone</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">_config.timeZone</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">TIMEZONE</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>334</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">locale</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">_config</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">_config.locale</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">_config.locale</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">LOCALE</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>335</span> 
<span class='line'>336</span> </span><span class="WHIT">	</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">airlift.isDefined</span><span class="PUNC">(</span><span class="NAME">date</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>337</span> </span><span class="WHIT">	</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>338</span> </span><span class="WHIT">		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">calendar</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Packages.java.util.Calendar.getInstance</span><span class="PUNC">(</span><span class="NAME">timeZone</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">locale</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>339</span> </span><span class="WHIT">		</span><span class="NAME">calendar.setTime</span><span class="PUNC">(</span><span class="NAME">date</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>340</span> </span><span class="WHIT">		</span><span class="NAME">calendar.setTimeZone</span><span class="PUNC">(</span><span class="NAME">timeZone</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>341</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>342</span> </span><span class="WHIT">	</span><span class="KEYW">else</span><span class="WHIT">
<span class='line'>343</span> </span><span class="WHIT">	</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>344</span> </span><span class="WHIT">		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">calendar</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Packages.java.util.Calendar.getInstance</span><span class="PUNC">(</span><span class="NAME">timeZone</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">locale</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>345</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>346</span> 
<span class='line'>347</span> </span><span class="WHIT">	</span><span class="NAME">calendar.add</span><span class="PUNC">(</span><span class="NAME">dateOffsetType</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">dateOffset</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>348</span> 
<span class='line'>349</span> </span><span class="WHIT">	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">calendar</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>350</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>351</span> 
<span class='line'>352</span> </span><span class="NAME">airlift.audit</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">_data</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">_action</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">_id</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>353</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>354</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">auditTrail</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Packages.airlift.servlet.rest.AuditTrail</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>355</span> 
<span class='line'>356</span> </span><span class="WHIT">	</span><span class="NAME">auditTrail.id</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">airlift.g</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>357</span> </span><span class="WHIT">	</span><span class="NAME">auditTrail.domainId</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">_id</span><span class="PUNC">||</span><span class="NAME">ID</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>358</span> </span><span class="WHIT">	</span><span class="NAME">auditTrail.action</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">_action</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>359</span> </span><span class="WHIT">	</span><span class="NAME">auditTrail.method</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">METHOD</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>360</span> </span><span class="WHIT">	</span><span class="NAME">auditTrail.domain</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">DOMAIN_NAME</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>361</span> </span><span class="WHIT">	</span><span class="NAME">auditTrail.uri</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">URI</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>362</span> </span><span class="WHIT">	</span><span class="NAME">auditTrail.handlerName</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">HANDLER_NAME</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>363</span> </span><span class="WHIT">	</span><span class="NAME">auditTrail.data</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Packages.com.google.appengine.api.datastore.Text</span><span class="PUNC">(</span><span class="NAME">_data</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>364</span> </span><span class="WHIT">	</span><span class="NAME">auditTrail.userId</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">USER</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">USER.id</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>365</span> </span><span class="WHIT">	</span><span class="NAME">auditTrail.actionDate</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">airlift.createDate</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>366</span> </span><span class="WHIT">	</span><span class="NAME">auditTrail.recordDate</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">auditTrail.actionDate</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>367</span> 
<span class='line'>368</span> </span><span class="WHIT">	</span><span class="NAME">AUDIT_CONTEXT.insert</span><span class="PUNC">(</span><span class="NAME">auditTrail</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>369</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>370</span> 
<span class='line'>371</span> </span><span class="NAME">airlift.formatDate</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">_date</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">_mask</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">_timeZone</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>372</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>373</span> </span><span class="WHIT">	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">Packages.airlift.util.FormatUtil.format</span><span class="PUNC">(</span><span class="NAME">_date</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">_mask</span><span class="PUNC">||</span><span class="STRN">"MM-dd-yyyy"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">_timeZone</span><span class="PUNC">||</span><span class="NAME">TIMEZONE</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>374</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>375</span> 
<span class='line'>376</span> </span><span class="NAME">airlift.syncAirliftUser</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">_abstractUser</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">_syncFunction</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>377</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>378</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">airliftUserList</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">SECURITY_CONTEXT.collectByExternalUserId</span><span class="PUNC">(</span><span class="NAME">_abstractUser.externalUserId</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">10</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"externalUserId"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>379</span> 
<span class='line'>380</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">airliftUser</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">airliftUserList.isEmpty</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Packages.airlift.servlet.rest.AirliftUser</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">airliftUserList.get</span><span class="PUNC">(</span><span class="NUMB">0</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>381</span> 
<span class='line'>382</span> </span><span class="WHIT">	</span><span class="NAME">LOG.info</span><span class="PUNC">(</span><span class="STRN">"Airlift user list is: "</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">airliftUserList</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>383</span> </span><span class="WHIT">	</span><span class="NAME">LOG.info</span><span class="PUNC">(</span><span class="STRN">"Abstract user is: "</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">_abstractUser</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>384</span> </span><span class="WHIT">	</span><span class="NAME">LOG.info</span><span class="PUNC">(</span><span class="STRN">"Airlift user is: "</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">airliftUser</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>385</span> 
<span class='line'>386</span> </span><span class="WHIT">	</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">airliftUser</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">LOG.info</span><span class="PUNC">(</span><span class="STRN">"Airlift user role set:"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">airliftUser.roleSet</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>387</span> </span><span class="WHIT">	</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">_abstractUser</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">LOG.info</span><span class="PUNC">(</span><span class="STRN">"Abstract user role set:"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">_abstractUser.roleSet</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>388</span> 
<span class='line'>389</span> </span><span class="WHIT">	</span><span class="NAME">airliftUser.setFullName</span><span class="PUNC">(</span><span class="NAME">_abstractUser.fullName</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>390</span> </span><span class="WHIT">	</span><span class="NAME">airliftUser.setShortName</span><span class="PUNC">(</span><span class="NAME">_abstractUser.shortName</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>391</span> </span><span class="WHIT">	</span><span class="NAME">airliftUser.setExternalUserId</span><span class="PUNC">(</span><span class="NAME">_abstractUser.externalUserId</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>392</span> </span><span class="WHIT">	</span><span class="NAME">airliftUser.setEmail</span><span class="PUNC">(</span><span class="NAME">_abstractUser.email</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>393</span> 
<span class='line'>394</span> </span><span class="WHIT">	</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">_abstractUser.roleSet</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">_abstractUser.roleSet</span><span class="WHIT"> </span><span class="KEYW">instanceof</span><span class="WHIT"> </span><span class="NAME">Packages.java.util.Collection</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>395</span> </span><span class="WHIT">	</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>396</span> </span><span class="WHIT">		</span><span class="NAME">airliftUser.setRoleSet</span><span class="PUNC">(</span><span class="NAME">airlift.s</span><span class="PUNC">(</span><span class="NAME">_abstractUser.roleSet</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>397</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>398</span> </span><span class="WHIT">	</span><span class="KEYW">else</span><span class="WHIT">
<span class='line'>399</span> </span><span class="WHIT">	</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>400</span> </span><span class="WHIT">		</span><span class="NAME">airliftUser.setRoleSet</span><span class="PUNC">(</span><span class="NAME">airlift.s</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>401</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>402</span> 
<span class='line'>403</span> </span><span class="WHIT">	</span><span class="NAME">airliftUser.setActive</span><span class="PUNC">(</span><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>404</span> </span><span class="WHIT">	
<span class='line'>405</span> 	</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">_syncFunction</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>406</span> </span><span class="WHIT">	</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>407</span> </span><span class="WHIT">		</span><span class="NAME">_syncFunction</span><span class="PUNC">(</span><span class="NAME">airliftUser</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">_abstractUser</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>408</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>409</span> 
<span class='line'>410</span> </span><span class="WHIT">	</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">airliftUser.id</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>411</span> </span><span class="WHIT">	</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>412</span> </span><span class="WHIT">		</span><span class="NAME">SECURITY_CONTEXT.update</span><span class="PUNC">(</span><span class="NAME">airliftUser</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>413</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>414</span> </span><span class="WHIT">	</span><span class="KEYW">else</span><span class="WHIT">
<span class='line'>415</span> </span><span class="WHIT">	</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>416</span> </span><span class="WHIT">		</span><span class="NAME">SECURITY_CONTEXT.insert</span><span class="PUNC">(</span><span class="NAME">airliftUser</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>417</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>418</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>419</span> 
<span class='line'>420</span> </span><span class="NAME">airlift.email</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">_users</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">_message</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">_subject</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">_from</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>421</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>422</span> </span><span class="WHIT">	</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">_message</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT">
<span class='line'>423</span> </span><span class="WHIT">		  </span><span class="STRN">""</span><span class="PUNC">.</span><span class="NAME">equals</span><span class="PUNC">(</span><span class="NAME">_message</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT">
<span class='line'>424</span> </span><span class="WHIT">		  </span><span class="NAME">airlift.isWhitespace</span><span class="PUNC">(</span><span class="NAME">_message</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>425</span> </span><span class="WHIT">	</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>426</span> </span><span class="WHIT">		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">users</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">_users</span><span class="PUNC">||</span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>427</span> </span><span class="WHIT">		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">adminEmail</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">APP_NAME.toLowerCase</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"@appspot.com"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>428</span> </span><span class="WHIT">		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">from</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">_from</span><span class="PUNC">||</span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">email</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">adminEmail</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">fullName</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">"Admin"</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>429</span> </span><span class="WHIT">		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">subject</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">_subject</span><span class="PUNC">||</span><span class="STRN">"For your information"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>430</span> </span><span class="WHIT">		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">message</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">_message</span><span class="PUNC">||</span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>431</span> 
<span class='line'>432</span> </span><span class="WHIT">		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">properties</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Packages.java.util.Properties</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>433</span> </span><span class="WHIT">		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">session</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Packages.javax.mail.Session.getDefaultInstance</span><span class="PUNC">(</span><span class="NAME">properties</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>434</span> 
<span class='line'>435</span> </span><span class="WHIT">		</span><span class="NAME">users.forEach</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">_user</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>436</span> </span><span class="WHIT">		</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>437</span> </span><span class="WHIT">			</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">_user</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">_user.email</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>438</span> </span><span class="WHIT">			</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>439</span> </span><span class="WHIT">				</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">mimeMessage</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Packages.javax.mail.internet.MimeMessage</span><span class="PUNC">(</span><span class="NAME">session</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>440</span> 
<span class='line'>441</span> </span><span class="WHIT">				</span><span class="NAME">mimeMessage.setFrom</span><span class="PUNC">(</span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Packages.javax.mail.internet.InternetAddress</span><span class="PUNC">(</span><span class="NAME">from.email</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">from.fullName</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>442</span> </span><span class="WHIT">				</span><span class="NAME">mimeMessage.addRecipient</span><span class="PUNC">(</span><span class="WHIT">
<span class='line'>443</span> </span><span class="WHIT">										 </span><span class="NAME">Packages.javax.mail.Message.RecipientType.TO</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>444</span> </span><span class="WHIT">										 </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Packages.javax.mail.internet.InternetAddress</span><span class="PUNC">(</span><span class="NAME">_user.email</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">_user.fullName</span><span class="PUNC">||</span><span class="STRN">""</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>445</span> </span><span class="WHIT">				</span><span class="NAME">mimeMessage.setSubject</span><span class="PUNC">(</span><span class="NAME">subject</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>446</span> </span><span class="WHIT">				</span><span class="NAME">mimeMessage.setText</span><span class="PUNC">(</span><span class="NAME">message</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>447</span> 
<span class='line'>448</span> </span><span class="WHIT">				</span><span class="NAME">Packages.javax.mail.Transport.send</span><span class="PUNC">(</span><span class="NAME">mimeMessage</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>449</span> </span><span class="WHIT">			</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>450</span> </span><span class="WHIT">		</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>451</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>452</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>453</span> </span></pre></body></html>